package com.egao.common.publicly;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.egao.common.component.hubei.api.HuBeiApi;
import com.egao.common.component.wechat.WeChatUtils;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.company.entity.Company;
import com.egao.common.module.company.entity.Position;
import com.egao.common.module.company.entity.Recruit;
import com.egao.common.module.company.mapper.PositionMapper;
import com.egao.common.module.company.service.CompanyService;
import com.egao.common.module.company.service.PositionService;
import com.egao.common.module.company.service.RecruitService;
import com.egao.common.module.push.entity.PushMsg;
import com.egao.common.module.push.mapper.PushMsgMapper;
import com.egao.common.module.push.service.PushMsgService;
import com.egao.common.module.pushInformation.PushInformationConstants;
import com.egao.common.module.pushInformation.service.PushInformationPositionResultService;
import com.egao.common.module.pushInformation.service.PushInformationPositionService;
import com.egao.common.module.pushInformation.service.PushInformationService;
import com.egao.common.module.system.entity.College;
import com.egao.common.module.system.service.CollegeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author lym
 * @date 2024/7/29 15:01
 */
@Api(tags = "测试")
@RestController
@RequestMapping("${api}")
public class PubliclyTestController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private PositionService positionService;
    @Autowired
    private RecruitService recruitService;
    @Autowired
    private PushMsgService pushMsgService;
    @Autowired
    private PushInformationService pushInformationService;
    @Autowired
    private PushInformationPositionService pushInformationPositionService;
    @Autowired
    private PushInformationPositionResultService pushInformationPositionResultService;
    @Autowired
    private PositionMapper positionMapper;
    @Autowired
    private CollegeService collegeService;

    private final String KEY = "3QznFop8S@rG42snX6KpvFq0nbxiKm2#Pxqjka3u.VDUz";

    @GetMapping("/publicly/test/hubei/company")
    public JsonResult company(Integer id, String key) {
        if (!KEY.equals(key)) {
            return JsonResult.error();
        }

        List<Company> companyList = new ArrayList<>();
        Company company = companyService.getById(id);

        companyList.add(company);
        return HuBeiApi.pushCompany(companyList);
    }

    @GetMapping("/publicly/test/hubei/job")
    public JsonResult job(Integer id, String key) {
        if (!KEY.equals(key)) {
            return JsonResult.error();
        }

        List<Position> positionList = new ArrayList<>();
        Position position = positionService.getById(id);
        positionList.add(position);

        return HuBeiApi.pushJob(positionList);
    }

    @GetMapping("/publicly/test/hubei/recruit")
    public JsonResult recruit(Integer id, String key) {
        if (!KEY.equals(key)) {
            return JsonResult.error();
        }

        List<Recruit> recruitList = new ArrayList<>();
        Recruit recruit = recruitService.getById(id);
        recruitList.add(recruit);

        return HuBeiApi.pushRecruit(recruitList);
    }

    @GetMapping("/publicly/test/conversion-push")
    public JsonResult company(String key) {
//        if (!"WKWEdRzY7NFqBVk".equals(key)) {
//            return JsonResult.error("未知错误");
//        }

        // 所有职位
        List<Position> positionList = positionMapper.listAll();

        // 所有学院
        List<College> collegeList = collegeService.list();

        List<PushMsg> pushMsgGroup = pushMsgService.list(new LambdaQueryWrapper<PushMsg>()
                .eq(PushMsg::getCompanyFlag, "0")
                .eq(PushMsg::getAdminFlag, "0")
                .eq(PushMsg::getPushType, "0")
        );



        return JsonResult.ok();
    }
}
